﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Windows.Forms;

namespace AlgoLogicMessenger
{
    public partial class StartQuizCountdowncs : Form
    {        
        string path = "C://Images//StartQuizCountDown.swf";
        private Timer _timer;

        System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient();
        NetworkStream serverStream = default(NetworkStream);

        public StartQuizCountdowncs()
        {
            InitializeComponent();
            this.CenterToScreen();
            this.FormBorderStyle = FormBorderStyle.None;

            string ip = IP.Address;
            clientSocket.Connect(IP.Address, 8888);
            serverStream = clientSocket.GetStream();
            byte[] outStream = System.Text.Encoding.ASCII.GetBytes("" + "#");
            serverStream.Write(outStream, 0, outStream.Length);
            serverStream.Flush();

            PlayFlash(path);

            //delay 4 seconds before closing winform
            _timer = new Timer();
            _timer.Interval = 4000;
            _timer.Tick += (s, e) => this.Close();
            _timer.Start();

            //send msg to QuestionAnswer
            string msg = "@startFacilTimer|";

            byte[] outStream2 = System.Text.Encoding.ASCII.GetBytes(msg + "#");
            if (serverStream != null)
            {
                serverStream.Write(outStream2, 0, outStream2.Length);
                serverStream.Flush();
            }
        }

        public void PlayFlash(string path)
        {

            if (File.Exists(path))
            {
                // Play the file
                axShockwaveFlash1.LoadMovie(0, path);
                axShockwaveFlash1.Play();
            }

        }


    }
}
